package com.citycloud.ccuap.tc.yq.resultsymbol;

import static org.springframework.data.domain.Sort.Direction.DESC;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.citycloud.ccuap.commons.constants.GlobalOperateType;
import com.citycloud.ccuap.commons.json.JSONData;
import com.citycloud.ccuap.commons.openapi.controller.base.BaseController;
import com.citycloud.ccuap.commons.web.util.ResolveRequest;
import com.citycloud.ccuap.framework.mybatis.pagination.PageQuery;
import com.citycloud.ccuap.framework.util.StringUtil;
import com.citycloud.ccuap.tc.yq.entity.SysResultSymbol;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api("海搜结果结果中过滤-符号")
@RestController
@RequestMapping("/v1/yq/resultsymbol")
public class ResultSymbolController extends BaseController {
	@Autowired
    private IResultSymbolService resultSymbolService;
    
	
	/**
	 * 默认构造函数
	 */
	public ResultSymbolController() {
	}

	@ApiOperation("根据主键获取对象")
	@RequestMapping(value = "/findById", method = { RequestMethod.GET, RequestMethod.POST })
	public JSONData findById() throws Exception {
		String objId = getStringParameter("objId");
		SysResultSymbol sysResultSymbol = resultSymbolService.findById(objId);
		
		JSONData jsonData = new JSONData(sysResultSymbol);
		return jsonData;
	}
	
	/**
	 * 获取页面提交的对象
	 * 
	 * @return struts result
	 * @throws Exception
	 */
	private SysResultSymbol getRequestDataObject(short operateType) throws Exception {
		SysResultSymbol sysResultSymbol = new SysResultSymbol();
		ResolveRequest.fillData(request, sysResultSymbol);
		if (GlobalOperateType.ADD == operateType) {
		} else if (GlobalOperateType.EDIT == operateType) {
		}

		return sysResultSymbol;
	}
	
	@ApiOperation("新增对象")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public JSONData add() throws Exception {
		SysResultSymbol sysResultSymbol = getRequestDataObject(GlobalOperateType.ADD);
		resultSymbolService.insert(sysResultSymbol);

		JSONData jsonData = new JSONData("添加海搜结果结果中过滤-符号成功！");
		return jsonData;
	}

	@ApiOperation("更新对象")
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public JSONData update() throws Exception {
		SysResultSymbol sysResultSymbol = getRequestDataObject(GlobalOperateType.EDIT);
		resultSymbolService.update(sysResultSymbol);

		JSONData jsonData = new JSONData("修改海搜结果结果中过滤-符号成功！");
		return jsonData;
	}
	

	@ApiOperation("删除对象")
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public JSONData delete() throws Exception {
		String objId = getStringParameter("objId");
		resultSymbolService.deleteById(objId);
		
		JSONData jsonData = new JSONData("删除海搜结果结果中过滤-符号成功！");
		return jsonData;
	}
	
	@ApiOperation("删除多个对象")
	@RequestMapping(value = "/deleteList", method = RequestMethod.POST)
	public JSONData deleteList() throws Exception {
		String objIds = getStringParameter("objIds");
		List<String> objIdList = StringUtil.strToStringList(objIds);
		
		resultSymbolService.deleteIdList(objIdList);
		
		JSONData jsonData = new JSONData("删除海搜结果结果中过滤-符号成功！");
		return jsonData;
	}

	@ApiOperation("根据条件查询对象")
	@RequestMapping(value = "/query", method = { RequestMethod.GET, RequestMethod.POST })
	public JSONData query() throws Exception {
		PageQuery<SysResultSymbol> pageQuery = ResolveRequest.getPageForParams(request);
		SysResultSymbolDTO sysResultSymbolDTO = new SysResultSymbolDTO();
		ResolveRequest.fillData(request, sysResultSymbolDTO, "q_", true);

		Sort sort = Sort.by(DESC, "objId");
//		Sort sort = new Sort(DESC, "objId");
		pageQuery.setSort(sort);
		
		
		PageQuery<SysResultSymbol> pageData = resultSymbolService.selectPage(pageQuery, sysResultSymbolDTO);
		
		JSONData jsonData = new JSONData(pageData);
		return jsonData;
	}

	@ApiOperation("cykablyat")
	@RequestMapping(value = "/cykablyat", method = { RequestMethod.GET, RequestMethod.POST })
	public JSONData cykablyat() throws Exception {
		JSONData jsonData = new JSONData(resultSymbolService.cykaBlyat());
		return jsonData;
	}
}